using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;

namespace Metro.Admin.BusinessEntities
{
    [DataContract]
    public class Customer
    {
        public Customer()
        {

        }

        public Customer(string name, string sureName,string id,string cityId, string cityName,string nemotechnic, string documentType, State state,CustomerType customerType,string document)
        {
            this.id = id;
            this.cityId = cityId;
            this.cityName = cityName; 
            this.technicalName = nemotechnic;
            this.documentType = documentType;
            this.state = state;
            this.customerType = customerType;
            this.documentNumber = document;
            this.name = name;
            this.sureName = sureName; 
        }

        private decimal avgBuy=0;
        private decimal avgSell=0;
        private decimal buyCredit=0;
        private string documentNumber=string.Empty;
        private string documentType=string.Empty;
        private string id=string.Empty;
        private decimal position=0;
        private decimal profit=0;
        private decimal sellCredit=0;
        private decimal commission = 0;
        private string technicalName=string.Empty;
        private decimal transitBuyCredit=0;
        private decimal transitSellCredit=0;
        private string cityId = string.Empty;
        private string cityName = string.Empty;  
        private State state;
        private CustomerType customerType;
        private string name=string.Empty;
        private string sureName =string.Empty;
        private bool payTaxes = false;

        [DataMember]
        public String Id
        {
            get { return this.id; }
            set { this.id = value; }
        }

        [DataMember]
        public String Name
        {
            get { return this.name;}
            set { this.name = value;}
        }

        [DataMember]
        public String SureName
        {
            get { return this.sureName; }
            set { this.sureName = value; }
        }

        [DataMember]
        public String TechnicalName
        {
            get { return this.technicalName; }
            set { this.technicalName = value; }
        }

        [DataMember]
        public Decimal Commission
        {
            get { return this.commission; }
            set { this.commission = value; }
        }

        [DataMember]
        public Boolean PayTaxes
        {
            get { return this.payTaxes; }
            set { this.payTaxes = value; }
        }

        [DataMember]
        public String DocumentNumber
        {
            get { return this.documentNumber; }
            set { this.documentNumber = value; }
        }

        [DataMember]
        public Decimal AvgBuy
        {
            get { return this.avgBuy; }
            set { this.avgBuy = value; }
        }

        [DataMember]
        public Decimal AvgSell
        {
            get { return this.avgSell; }
            set { this.avgSell = value; }
        }

        [DataMember]
        public Decimal BuyCredit
        {
            get { return this.buyCredit; }
            set { this.buyCredit = value; }
        }

        [DataMember]
        public Decimal Position
        {
            get { return this.position; }
            set { this.position = value; }
        }

        [DataMember]
        public Decimal Profit
        {
            get { return this.profit; }
            set { this.profit = value; }
        }

        [DataMember]
        public Decimal SellCredit
        {
            get { return this.sellCredit; }
            set { this.sellCredit = value; }
        }

        [DataMember]
        public  Decimal TransitBuyCredit
        {
            get { return this.transitBuyCredit; }
            set { this.transitBuyCredit = value; }
        }

        [DataMember]
        public Decimal TransitSellCredit
        {
            get { return this.transitSellCredit; }
            set { this.transitSellCredit = value; }
        }
        
        public State State
        {
            get { return this.state; }
            set { this.state = value; }
        }

        public CustomerType CustomerType
        { 
            get { return this.customerType; }
            set { this.customerType = value; }
        }

        [DataMember]
        public String DocumentType
        {
            get { return this.documentType; }
            set { this.documentType = value; }
        }

        [DataMember]
        public String StringState
        {
            get { return CustomerServices.State2String(this.state); }
            set { this.state = CustomerServices.GetState(value); }
        }

        [DataMember]
        public String StringCustomerType
        {
            get { return CustomerServices.CustomerType2StringLong(this.customerType); }
            set { this.customerType = CustomerServices.GetCustomerTypeLong(value); }
        }

        [DataMember]
        public String CityId
        {
            get { return this.cityId ; }
            set { this.cityId = value; }
        }

        [DataMember]
        public String CityName
        {
            get { return this.cityName; }
            set { this.cityName = value; }
        }
    }

    [DataContract(Name = "CustomerType")]
    public enum CustomerType
    {
        [EnumMember] 
        Cambiario,
        [EnumMember] 
        OPCF
    }

    [DataContract(Name = "State")]
    public enum State
    {
        [EnumMember] 
        Active,
        [EnumMember]
        Inactive
    }

    public static class CustomerServices
    {
        //public static DocumentType GetDocumentType(string documentType)
        //{
        //    DocumentType documentTypeValue = DocumentType.CC;

        //    if (documentType.Equals("NIT"))
        //        documentTypeValue = DocumentType.NIT;

        //    if (documentType.Equals("CC"))
        //        documentTypeValue = DocumentType.CC;

        //    return documentTypeValue;
        //}

        public static CustomerType GetCustomerTypeLong(string customerType)
        {
            CustomerType customerTypeValue = CustomerType.Cambiario;

            if (customerType.Equals("Cambiario"))
                customerTypeValue = CustomerType.Cambiario;

            if (customerType.Equals("OPCF"))
                customerTypeValue = CustomerType.OPCF;

            return customerTypeValue;
        }
        public static CustomerType GetCustomerType(string customerType)
        {
            CustomerType customerTypeValue = CustomerType.Cambiario;

            if (customerType.Equals("C"))
                customerTypeValue = CustomerType.Cambiario;

            if (customerType.Equals("O"))
                customerTypeValue = CustomerType.OPCF;

            return customerTypeValue;
        }

        public static string CustomerType2String(CustomerType customerType)
        {
            string customerTypeString = string.Empty;  
           
            if (customerType.Equals(CustomerType.Cambiario))
                customerTypeString = "C";

            if (customerType.Equals(CustomerType.OPCF))
                customerTypeString = "O";

            return customerTypeString;
        }

        public static string CustomerType2StringLong(CustomerType customerType)
        {
            string customerTypeString = string.Empty;

            if (customerType.Equals(CustomerType.Cambiario))
                customerTypeString = "Cambiario";

            if (customerType.Equals(CustomerType.OPCF))
                customerTypeString = "OPCF";

            return customerTypeString;
        }

        //public static string DocumentType2String(DocumentType documentType)
        //{
        //    string documentTypeString = string.Empty;

        //    if (documentType.Equals(DocumentType.CC))
        //        documentTypeString = "CC";

        //    if (documentType.Equals(DocumentType.NIT))
        //        documentTypeString = "NIT";

        //    return documentTypeString;
        //}

        public static State GetState(string state)
        {
            State stateValue = State.Active;

            if (state.Equals("A"))
                stateValue = State.Active;

            if (state.Equals("I"))
                stateValue = State.Inactive;

            return stateValue;
        }

        public static string State2String(State state)
        {
            string stateString = string.Empty ;

            if (state.Equals(State.Active))
                stateString = "A";

            if (state.Equals(State.Inactive))
                stateString = "I";

            return stateString;
        }

        public static string GetTechnicalName()
        {
            string retTechName = string.Empty;
            Guid seed = Guid.NewGuid();
            retTechName = seed.ToString();
            return retTechName.Substring(0, 5);   
        }
    }

}
